﻿namespace iFinance.Infrastructure.ViewModels
{
    using System;
    using System.Collections.ObjectModel;
    using iFinance.Entity;
    using Microsoft.Practices.Prism.ViewModel;

    /// <summary>
    /// 消费品项ViewModel
    /// </summary>
    public class ConsumableItemViewModel : NotificationObject
    {
        #region Ctor

        public ConsumableItemViewModel()
            : this(new Consumable())
        {
        }

        public ConsumableItemViewModel(Consumable consumable)
        {
            this.RealData = consumable;
        }

        #endregion

        #region 属性

        /// <summary>
        /// 代理的真实数据
        /// </summary>
        public Consumable RealData { get; private set; }

        /// <summary>
        /// 消费品唯一编号
        /// </summary>
        public int ID
        {
            get { return RealData.ID; }
            set
            {
                if (RealData.ID != value)
                {
                    RealData.ID = value;
                    RaisePropertyChanged(() => this.ID);
                }
            }
        }      

        /// <summary>
        /// 消费品名称
        /// </summary>
        public string Name
        {
            get { return RealData.Name; }
            set
            {
                if (RealData.Name != value)
                {
                    RealData.Name = value;
                    RaisePropertyChanged(() => this.Name);
                }
            }
        }

        /// <summary>
        /// 消费品类型唯一编号
        /// </summary>
        public int TypeID
        {
            get { return RealData.TypeID; }
            set
            {
                if (RealData.TypeID != value)
                {
                    RealData.TypeID = value;
                    RaisePropertyChanged(() => this.TypeID);
                }
            }
        }

        /// <summary>
        /// 上次购买时的单价
        /// </summary>
        public decimal LastUnitPrice
        {
            get { return RealData.LastUnitPrice; }
            set
            {
                if (RealData.LastUnitPrice != value)
                {
                    RealData.LastUnitPrice = value;
                    RaisePropertyChanged(() => this.LastUnitPrice);
                }
            }
        }

        /// <summary>
        /// 上次购买日期
        /// </summary>
        public DateTime LastPurchaseDate
        {
            get { return RealData.LastPurchaseDate; }
            set
            {
                if (RealData.LastPurchaseDate != value)
                {
                    RealData.LastPurchaseDate = value;
                    RaisePropertyChanged(() => this.LastPurchaseDate);
                }
            }
        }

        /// <summary>
        /// 描述
        /// </summary>
        public string Description
        {
            get { return RealData.Description; }
            set
            {
                if (RealData.Description != value)
                {
                    RealData.Description = value;
                    RaisePropertyChanged(() => this.Description);
                }
            }
        }

        /// <summary>
        /// 购买过的总数量
        /// </summary>
        public decimal TotalCount
        {
            get { return RealData.TotalCount; }
            set
            {
                if (RealData.TotalCount != value)
                {
                    RealData.TotalCount = value;
                    RaisePropertyChanged(() => this.TotalCount);
                }
            }
        }

        #endregion
    }

    /// <summary>
    /// 消费品集合ViewModel
    /// </summary>
    public class ConsumableListViewModel : ObservableCollection<ConsumableItemViewModel>
    {
    }
}
